
#include "Input.h"

namespace smartvoice {

REGISTER_SERVICE("input", Input);

/////////////////////////////////////////////////////////////////////////////

NEBULA_ERROR_CODE Input::OnInitialize()
{
	NEBULA_ERROR_CODE rc;

	if (NEBULA_ERR_SUCCESS != (rc = InitializeGenerator(
					"/var/spool/nebula/data/smartvoice/input-backup",
					"/var/spool/nebula/data/smartvoice/input-dead",
					"session",
					"ack")))
		return rc;

	RegisterUpdateSlot("input", SessionTask::Allocator, raw_input_handler);
	return NEBULA_ERR_SUCCESS;
}

NEBULA_ERROR_CODE Input::OnStart()
{
	return StartGenerator();
}

void Input::OnStop()
{
	StopGenerator();
}

void Input::OnFinalize()
{
	FinalizeGenerator();
}

ITask* Input::AllocateTask()
{
	return SessionTask::Allocator(this);
}

ITask* Input::ForkTask(ITask*, const char*)
{
	// does not have to implement as no fork
	return 0;
}

/////////////////////////////////////////////////////////////////////////////

NEBULA_ERROR_CODE Input::raw_input_handler(IService* service, IRequest* request, ITask* intask, ITask** outtask)
{
	SessionTask *task = static_cast<SessionTask*>(intask);
	return (static_cast<Input*>(service))->raw_input_handler(task);
}

NEBULA_ERROR_CODE Input::raw_input_handler(SessionTask* task)
{
	SessionTask* dup = task->Clone();
	return HandleTask(dup);
}

} // namespace smartvoice

